/* Copyright 2006, 2007 Christophe Jeannin

    This file is part of xch.

    xch is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    xch is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with xch; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <gtk/gtk.h>
#include <string.h>

#ifdef G_OS_WIN32
#	include <winsock.h>
#elif defined G_OS_UNIX
#	include <sys/socket.h>
#	include <sys/select.h>
#	include <netinet/in.h>
#	include <arpa/inet.h>
#endif


#define XCH_ABORT		0
#define XCH_LISTEN		1
#define XCH_CONNECT		2

#define XCH_PORT		htons(12006)
#define XCH_TEST		htonl(0x74657374)		/* the 4 characters "test" */
#define XCH_OK			htons(0x4F4B)			/* the 2 characters "OK" */
#define XCH_QUIT		htonl(0x0601F1F6)
#define XCH_DEF_SERVER	"192.168.0.2"	/* default server */


typedef struct _xchutils
{
	char buffer[512];
	GtkWidget* startup;
	GtkWidget* mainw;
	GtkWidget* radio;
	GtkWidget* entry;
	GtkWidget* text;
	GtkTextBuffer* txtbuf;
	int mode;
	guint32 ip;
	int tehsock;
} xchutils;


void startup_init();
void main_init();
void destroy_mainw(GtkWidget *widget, gpointer data);
void go_handler(GtkWidget *widget, gpointer data);
void send_handler(GtkWidget *widget, gpointer data);
gboolean socket_handler(gpointer data);
int connect_proc();
int listen_proc();

#ifdef G_OS_WIN32
	int __stdcall FreeConsole();
#endif